app.controller('houseAdmCtrl', ['$scope', '$rootScope', 'pcdService', 'listSve', '$timeout','$filter', function($scope, $rootScope, pcdService, listSve, $timeout,$filter) {
	$rootScope.navIndex = 1;

	//获取baseURL
	//	$scope.oBaseUrl = listSve.returnBase();
	document.getElementById('houseExportByUnit').action = listSve.outList();
	//获取省列表
	$scope.getPro = function() {
		pcdService.prolist().list().then(function(e) {
			$scope.prolist = e.data;
		})
		pcdService.citylist().list().then(function(e) {
			$scope.oCityList = e.data;
		})
		pcdService.dislist().list().then(function(e) {
			$scope.oDisList = e.data;
		})
	}
	$scope.getPro();
	//省市区联动
	$scope.proFunc = function(e) {
		console.info(e)
		var proId = e;
		//e.data
		$scope.citylist = new Array;
		$scope.cty = '';
		$scope.dis = '';
		$scope.dislist = '';
		for(var i = 0; i < $scope.oCityList.length; i++) {
			if($scope.oCityList[i].pro_id == proId) {
				$scope.citylist.push($scope.oCityList[i]);
			}
		}
	}
	$scope.ctyFunc = function(e) {
			var ctyId = e;
			//e.data
			$scope.dislist = new Array;
			$scope.dis = '';
			for(var i = 0; i < $scope.oDisList.length; i++) {
				if($scope.oDisList[i].city_id == ctyId) {
					$scope.dislist.push($scope.oDisList[i]);
				}
			}
		}
		//$scope.pageInx = {pageNum:1,numPerPage:1};
		//列表
	$scope.getItem = function() {
		listSve.hList().list({
			numPerPage: 20
		}).then(function(e) {
			console.info(e);
			$scope.list = e.res.data;
			var count = Math.ceil(e.res.page.recordCount / 20);
			$scope.count = count;
			console.info($scope.count);
			var pager = new Pager({
				index: 1,
				total: $scope.count,
				parent: pagerBox_1,
				onchange: changePage
			});

		});
	}
	$scope.first = true;
	$scope.getItem();
	var pagerBox_1 = document.getElementById('pager_2');
	//分页器
	//$scope.count = Math.ceil(e.count[0].count/$scope.page.size);
	function changePage(obj) {
		if($scope.first) {
			$scope.first = false;
		} else {
			console.info(obj.index)
			$scope.pageInx = {
				pageNum: obj.index,
				numPerPage: 20
			};
			//				$scope.getItem();
			listSve.hList().list($scope.pageInx).then(function(e) {
				console.info(e);
				$scope.list = e.res.data;

			})
		}

	}
	//c查询详情
	$scope.alLook = function(e) {
		$('#oRadio').prop({"checked":false});
			//pageNum:1 oDetail
			//numPerPage:50
			console.info(e)
			$scope.districtId = {
				districtId: e.id
			};
			$scope.e = e;
			listSve.oDetail().list($scope.districtId).then(function(e) {
				console.info(e);
					var map = {};
				for(var i = 0; i < e.res.data.length; i++) {
	
					var h = e.res.data[i];
					var key = h.floorNo + "_" + h.unit + "";
	
					if(!map[key]) {
						var damenObj = {};
						for(var j = 0; j < e.res.data.length; j++) {
							var h1 = e.res.data[j];
							var key2 = h1.floorNo + "_" + h1.unit + "";
							if(!h1.door && key == key2) {
								//大门
								var id = h1.roomNo;
								var doorList = new Array();
								for(var k = 0; k < e.res.data.length; k++) {
									var h2 = e.res.data[k];
									if(h2.roomNo === id) {
										doorList.push(h2.door);
									}
								}
								damenObj[h1.roomNo] = doorList;
								//							continue go;
							}
						}
						map[key] = damenObj;
					}
				}
				$scope.oMap = map;
				console.info($scope.oMap)

			})
		

		}
		//折叠
	$scope.isCollapsed = false;

	//搜索
	$scope.sear_1 = function(pro, cty, dis, uName, uDress) {
		$scope.first_2 = true;
		$scope.allSear = {};
		$scope.allSear.provinceName = $filter('proName')(pro, $scope.prolist);
		$scope.allSear.cityName = $filter('cityName')(cty, $scope.oCityList);
		$scope.allSear.distName = $filter('disName')(dis, $scope.oDisList);
//		$scope.allSear.type = way;
		$scope.allSear.districtName = uName;
		$scope.allSear.street = uDress;
		$scope.allSear.numPerPage = 20;
		console.info($scope.allSear)
		listSve.hList().list($scope.allSear).then(function(e) {
			console.info(e)
			$scope.list = e.res.data;
			var count = Math.ceil(e.res.page.recordCount / 20);
			$scope.count = count;
			pagerBox_1.innerHTML = "";
			var pager = new Pager({
				index: 1,
				total: $scope.count,
				parent: pagerBox_1,
				onchange: doChangePage_2
			});

		})
	}
	
	//搜索分页器
	function doChangePage_2(obj) {
		if($scope.first_2) {
			$scope.first_2 = false;
		} else {
			console.info(obj.index)
			$scope.allSear.pageNum = obj.index;
			//$scope.pageInx = {pageNum:obj.index,numPerPage:20,provinceId:9};
			//				$scope.getItem();
			listSve.hList().list($scope.allSear).then(function(e) {
				console.info(e);
				$scope.list = e.res.data;

			})
		}
	}
	//导出xsl表---------------------//
	//	 var strs= new Array(); //定义一数组 
	//			var strs=x.split("_"); //字符分割 
	//  		return strs[1];
	$scope.allUnit = {};
	$scope.updateSelection = function($event, id) {
			console.info($event)
			$event.stopPropagation();
			var checkbox = $event.target;
			var checked = checkbox.checked;
			// console.info(checked)
			if(checked) {
				$scope.allUnit.floorNo = id.split("_")[0]
				$scope.allUnit.unit = id.split("_")[1]

			}
		}
		//	 $scope.outExcel = function(a){
		//	 	//{{e.districtName}}{{e.houseStreet.provinceId}}{{e.houseStreet.cityId}}{{e.houseStreet.dist}}{{e.houseStreet.street}}
		//	 	//console.info('小区address:'+a.houseStreet.provinceId+a.houseStreet.cityId+a.houseStreet.dist+a.houseStreet.street+a.districtName)
		//	 	//console.info('小区houseDistrictId:'+a.id)
		//	 	$scope.allUnit.houseDistrictId = a.id;
		//	 	$scope.allUnit.address = a.houseStreet.provinceId+a.houseStreet.cityId+a.houseStreet.dist+a.houseStreet.street+a.districtName;
		//	 	console.info($scope.allUnit)
		//
		//	 	
		//	 }
	$scope.warn = function(e){
		console.info(e)
	}

}])